Karma Toolkit Architecture
Rendering
and User Interaction is where external inputs to the system are entered, for example, turning
motors on and off. Also the scene can be drawn to the screen by the renderer.
McdModels is the set of all of the models, each of which references a geometry. Each model contains its AABB (axis aligned bounding box).
McdGeometries are the actual collision geometry and may be aggregates of simple shapes. Each geometry can be used by many models
McdSpace contains all of the models, including a list of ModelPairs that might be touching.
McdSpaceGetPairs is a part of collision called by the Bridge. It takes the list of pairs that might be touching and puts them into the correct categories of the McdModelPairContainer.
McdModelPairContainer is a temporary data store containing three main groups:
1) Hello pairs – are pairs whose bounding boxes are in the first frame of
overlapping.
2) Staying pairs – are pairs that have overlapped for more than one frame.
3) Goodbye pairs – are pairs that used to overlap, but no longer do.
MstHandleTransitions is a section that looks at the Hello and Goodbye pairs only. For Hello pairs, MstHandleTransitions looks up the corresponding element in the McdInteractionTable. Each element has three function pointers:
1) The pointer to the Hello function for that pair of objects, this allocates data for the intersection test if necessary.
2) The pointer to the intersection test itself. Given a pair of geometries, it will deduce whether the objects are touching or not, and if they are it will calculate the collision contacts for that ModelPair.
3) The pointer to the Goodbye function which deallocates anything the hello function allocates.
The group of three function pointers are an McdInteraction structure. For each Hello pair, the pointer to the correct McdInteraction structure is stored in the Modelpair.
For Hello pairs, MstHandleTransitions calls the Hello function.
For Goodbye pairs, MstHandleTransitions calls the goodbye function. Also it looks for any contact groups and if they are present it destroys them.
1) MdtContactParams – which contains friction, restitution etc.
2) Callbacks – these are intersect, per pair and contact callbacks for manually tweaking contact parameters.
MstHandleCollisions uses the Hello and Staying lists, it takes each ModelPair in turn, calls McdIntersect for the particular model pair in question. This function is used to generate a set of collision contacts (McdContact) containing:
1) Position
2) Normal
3) Penetration
The collision contacts are then turned into dynamics contacts (MdtContact), which have parameters like friction, restitution etc. This done with reference to the MstMaterialTable which also includes optional call backs for manual tweaking.
MdtWorldUpdatePartitions takes all of the bodies and constraints and puts them into sets that can be simulated as a group without affecting any of the other sets. These sets get stored in MdtPartitionOutput.
MdtAutoDisable looks at each partition in turn and if its velocity and acceleration is less than a threshold value it is disabled. The partition is then removed from the output as it is not required to be simulated. Also the corresponding collision model is frozen.
MdtPack changes the list of bodies and constraints; it uses the correct basic constraint library (MdtBcl) function for each constraint and turns it into constraint rows (MdtKeaConstraints) to input into Kea [note: different constraint types in ŕ same format out].
MdtKeaSolve takes in bodies and constraint rows from MdtKeaBodies/MdtKeaConstraints and calculates the correct forces to satisfy the constraints rows. (Using velocities, masses of bodies etc).
MdtKeaIntegrate moves the bodies after the forces have been determined by MdtKeaSolve. I.e. given the total force, mass, time step, initial velocity and initial position of the body it updates the body’s position.